package ants.map;

public class Coordinate implements Comparable<Coordinate> {

	private final int col;
	private final String coordinateString;
	private final int hashCode;
	private final int row;

	public Coordinate(int row, int col) {
		this.row = row;
		this.col = col;
		this.coordinateString = String.format("(%s,%s)", this.row, this.col);
		this.hashCode = coordinateString.hashCode();
	}

	public int col() {
		return col;
	}

	@Override
	public int compareTo(Coordinate o) {
		int cmp = new Integer(row).compareTo(o.row);
		if (cmp == 0)
			cmp = new Integer(col).compareTo(o.col);
		return cmp;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Coordinate) {
			return this.row == ((Coordinate) obj).row
					&& this.col == ((Coordinate) obj).col;
		} else
			return false;
	}

	@Override
	public int hashCode() {
		return hashCode;
	}

	public int row() {
		return row;
	}

	@Override
	public String toString() {
		return coordinateString;
	}

}
